package com.haoze.nurse.enumeration;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * 医疗术语类型枚举。
 * @author maxl
 * @time 2019-05-02。
 */
public class MedicalTypeEnum {

    private String enumValue;
    private String enumName;
    private final static Map<String, MedicalTypeEnum> enumMap = new HashMap();

    /**
     * 勾选项。
     */
    public final static MedicalTypeEnum CheckType = new MedicalTypeEnum("5","勾选项");
    /**
     * 多项选择。
     */
    public final static MedicalTypeEnum MultipleSelect  = new MedicalTypeEnum("7","多项选择");

    /**
     * 数字。
     */
    public final static MedicalTypeEnum NumberType = new MedicalTypeEnum("2","数字");
    /**
     * 字符串。
     */
    public final static MedicalTypeEnum StringType = new MedicalTypeEnum("1","字符串");
    /**
     * 日期类型。
     */
    public final static MedicalTypeEnum DateType = new MedicalTypeEnum("3","日期类型");
    /**
     * 数据组。
     */
    public final static MedicalTypeEnum DataGroup = new MedicalTypeEnum("4","数据组");
    /**
     * 术语。
     */
    public final static MedicalTypeEnum Term = new MedicalTypeEnum("20","术语");
    /**
     * 值域。
     */
    public final static MedicalTypeEnum Range = new MedicalTypeEnum("21","值域");
    /**
     * 字典。
     */
    public final static MedicalTypeEnum Dictionary = new MedicalTypeEnum("22","字典");
    /**
     * 单项选择。
     */
    public final static MedicalTypeEnum SingleSelect = new MedicalTypeEnum("6","单项选择");

    private MedicalTypeEnum(String enumValue, String enumName){
        this.enumValue = enumValue;
        this.enumName = enumName;
    }

    public static MedicalTypeEnum fromValue(String enumValue){
        if(enumMap.size() == 0) {
            putSourceEnum();
        }
        return enumMap.get(enumValue);
    }

    private static void  putSourceEnum(){

        Class clazz = MedicalTypeEnum.class;
        Field[] fields = clazz.getDeclaredFields();
        MedicalTypeEnum enumClass = null;
        for(Field field : fields) {
            if(field.getType().equals(clazz)) {
                try {
                    enumClass = (MedicalTypeEnum)field.get(null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if(enumClass != null) {
                    enumMap.put(enumClass.getEnumValue(),enumClass);
                }
            }
        }
    }


    public String getEnumValue() {
        return enumValue;
    }

    public String getEnumName() {
        return enumName;
    }
}
